/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachinesystem.impl;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import warmachinesystem.ArmyList;
import warmachinesystem.BaseUnit;
import warmachinesystem.BaseUnitTierElement;
import warmachinesystem.UnitKind;
import warmachinesystem.WarmachineSystemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Base Unit Tier Element</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachinesystem.impl.BaseUnitTierElementImpl#getUnitType <em>Unit Type</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitTierElementImpl#getUnitTag <em>Unit Tag</em>}</li>
 *   <li>{@link warmachinesystem.impl.BaseUnitTierElementImpl#getUnitKind <em>Unit Kind</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BaseUnitTierElementImpl extends EObjectImpl implements BaseUnitTierElement {
	/**
	 * The cached value of the '{@link #getUnitType() <em>Unit Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitType()
	 * @generated
	 * @ordered
	 */
	protected BaseUnit unitType;

	/**
	 * The default value of the '{@link #getUnitTag() <em>Unit Tag</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitTag()
	 * @generated
	 * @ordered
	 */
	protected static final String UNIT_TAG_EDEFAULT = "";

	/**
	 * The cached value of the '{@link #getUnitTag() <em>Unit Tag</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitTag()
	 * @generated
	 * @ordered
	 */
	protected String unitTag = UNIT_TAG_EDEFAULT;

	/**
	 * The default value of the '{@link #getUnitKind() <em>Unit Kind</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitKind()
	 * @generated NOT
	 * @ordered
	 */
	protected static final UnitKind UNIT_KIND_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getUnitKind() <em>Unit Kind</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUnitKind()
	 * @generated
	 * @ordered
	 */
	protected UnitKind unitKind = UNIT_KIND_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BaseUnitTierElementImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachineSystemPackage.Literals.BASE_UNIT_TIER_ELEMENT;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BaseUnit getUnitType() {
		if (unitType != null && unitType.eIsProxy()) {
			InternalEObject oldUnitType = (InternalEObject)unitType;
			unitType = (BaseUnit)eResolveProxy(oldUnitType);
			if (unitType != oldUnitType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE, oldUnitType, unitType));
			}
		}
		return unitType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public BaseUnit basicGetUnitType() {
		return unitType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUnitType(BaseUnit newUnitType) {
		BaseUnit oldUnitType = unitType;
		unitType = newUnitType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE, oldUnitType, unitType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getUnitTag() {
		return unitTag;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUnitTag(String newUnitTag) {
		String oldUnitTag = unitTag;
		unitTag = newUnitTag;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TAG, oldUnitTag, unitTag));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public UnitKind getUnitKind() {
		return unitKind;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUnitKind(UnitKind newUnitKind) {
		UnitKind oldUnitKind = unitKind;
		unitKind = newUnitKind == null ? UNIT_KIND_EDEFAULT : newUnitKind;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_KIND, oldUnitKind, unitKind));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public EList<BaseUnit> getAffectedUnits(ArmyList armyList) {
		EList<BaseUnit> result = new BasicEList<BaseUnit>();
		if (getUnitType() != null){
			result.add(getUnitType());
		} else if(getUnitKind()!= null){
			result.addAll(armyList.getBaseUnitsByTag(getUnitTag(), getUnitKind()));
		} else if(getUnitTag() != null && !"".equals(getUnitTag())){
			result.addAll(armyList.getBaseUnitsByTag(getUnitTag()));
		}
		
		return result;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE:
				if (resolve) return getUnitType();
				return basicGetUnitType();
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TAG:
				return getUnitTag();
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_KIND:
				return getUnitKind();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE:
				setUnitType((BaseUnit)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TAG:
				setUnitTag((String)newValue);
				return;
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_KIND:
				setUnitKind((UnitKind)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE:
				setUnitType((BaseUnit)null);
				return;
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TAG:
				setUnitTag(UNIT_TAG_EDEFAULT);
				return;
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_KIND:
				setUnitKind(UNIT_KIND_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TYPE:
				return unitType != null;
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_TAG:
				return UNIT_TAG_EDEFAULT == null ? unitTag != null : !UNIT_TAG_EDEFAULT.equals(unitTag);
			case WarmachineSystemPackage.BASE_UNIT_TIER_ELEMENT__UNIT_KIND:
				return unitKind != UNIT_KIND_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (unitTag: ");
		result.append(unitTag);
		result.append(", unitKind: ");
		result.append(unitKind);
		result.append(')');
		return result.toString();
	}

} //BaseUnitTierElementImpl
